package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Author: suncf
 * @Data: 2023年03月06日 14:33
 * @Version: V1.0
 * @Description:TODO
 */
@Configuration
@Log4j2
public class FillDataConfig  implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("deptId", SecurityUtils.getLoginUser().getDeptId(),metaObject);
        this.setFieldValByName("createBy", SecurityUtils.getLoginUser().getUsername(), metaObject);
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateBy", SecurityUtils.getLoginUser().getUsername(), metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("delFlag","1",metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateBy", SecurityUtils.getLoginUser().getUsername(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
